package com.dzt.androidframework.view;

import android.os.Bundle;
import android.view.View;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.TitleFrameActivity;
import com.dzt.androidframework.databinding.ActivityClockBinding;

import java.util.Calendar;

/**
 * 出处：https://github.com/Lloyd0577/CustomClockForAndroid
 */
public class ClockActivity extends TitleFrameActivity<ActivityClockBinding> {

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}

	@Override
	protected int getLayoutId() {
		return R.layout.activity_clock;
	}

	@Override
	protected void initWidgets() {
		setTitle(getString(R.string.view_4));
		Calendar calendar = Calendar.getInstance();
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		int min = calendar.get(Calendar.MINUTE);
		int second = calendar.get(Calendar.SECOND);

		bindingView.timeView.setTime(hour, min, second);
		bindingView.timeView.start();
		bindingView.btnGetTime.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				int hour = bindingView.timeView.getHour();
				int minute = bindingView.timeView.getMin();
				int second = bindingView.timeView.getSecond();
				bindingView.etHour.setText(String.valueOf(hour));
				bindingView.etMinute.setText(String.valueOf(minute));
				bindingView.etSecond.setText(String.valueOf(second));
			}
		});
		bindingView.btnSetTime.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				int hour = Integer.parseInt(bindingView.etHour.getText().toString());
				int minute = Integer.parseInt(bindingView.etMinute.getText().toString());
				int second = Integer.parseInt(bindingView.etSecond.getText().toString());
				bindingView.timeView.setTime(hour, minute, second);
			}
		});
	}
}
